#include "QtBlendToEffect.h"
#include "QtSprite.h"

QtBlendToEffect::QtBlendToEffect(): target(0)
{
}

QtBlendToEffect::~QtBlendToEffect()
{
}

QtBlendToEffect::QtBlendToEffect(const QtBlendToEffect& rhs): QtSingleAnimationEffect(rhs), target(rhs.target), endAlpha(rhs.endAlpha), startAlpha(rhs.startAlpha)
{

}

void QtBlendToEffect::SetTarget(QtSprite *sprite)
{
	target = sprite;
}

QtSprite* QtBlendToEffect::Target() const
{
	return target;
}

void QtBlendToEffect::Update(qreal value)
{
	if (target)
	{	
		target->SetAlpha( startAlpha + (endAlpha-startAlpha)*value );
	}
}

void QtBlendToEffect::SetEndAlpha(qreal alpha)
{
	endAlpha = alpha;
}

void QtBlendToEffect::SetupAnimation()
{
	if (target)
	{
		startAlpha = target->Alpha();
	}
}

QtAnimationEffect* QtBlendToEffect::Clone() const
{
	return new QtBlendToEffect(*this);
}

